package cn.edu.leetcode.排序;

import java.util.Arrays;

public class 插入排序 {

    public static void main(String[] args) {
        int[] array = {9, 8, 7, 6, 5, 4, 3, 2, 1};
        insertSort(array);

        System.out.println(Arrays.toString(array));
    }

    public static void insertSort(int[] a) {
        int tmp;
        for (int i = 1; i < a.length; i++) {
            tmp = a[i];
            int j = i;
            while ( j >= 1 && tmp < a[j-1]) {
                a[j] = a[j-1];
                j--;
            }
            a[j] = tmp;
        }
    }
}
